package kuoge.practice.ch.delayqueue.consumer;

import com.ch.delayqueue.core.DelayQueueService;
import com.ch.delayqueue.core.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.concurrent.ThreadLocalRandom;

@Slf4j
@Service
public class OrderService {
    private final DelayQueueService delayQueueService;

    public OrderService(DelayQueueService delayQueueService) {
        this.delayQueueService = delayQueueService;
    }

    @PostConstruct
    public void  init() {
        final String orderNamespace = NamespaceConstants.ORDER_PAY_TIMEOUT;
        delayQueueService.executeWithFixedDelay(new Message(orderNamespace, "5", "fde123_" + ThreadLocalRandom.current().nextLong(9999)), 5);
        delayQueueService.executeWithFixedDelay(new Message(orderNamespace, "6", "fde456_" + ThreadLocalRandom.current().nextLong(9999)), 9);
        log.info("send message success");
    }
}
